#===============================================================================
# Koro Business Environment
# Copyright (C) 2008  Antonio Corroppoli
#
#This file is part of Koro BE.
# 
# Koro BE is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# Koro BE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Koro BE; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#===============================================================================
import gettext, os
from koro.settings import language

__lang = language.lower()
__langdir = os.path.join('.','lang')


# set default translation. File is searched under cwd()/__localedir/$LANG/LC_MESSAGES
# and in system default places.



def _(s,p=None,n=1):
    """ Default localization service. Translation is based on default
    gettext interface. Translation is returned in Unicode.

    Messages are searched first in application translations and in Dabo ones after.
    
    Translation files are searched in
    application.HomeDirectory/locale and system default locale
    directories accoding to gettext conventions(files must be
    placed under ${LANG}/LC_MESSAGES subdirectory. File basename must
    be appName or appName-appVersion in lower case.
    
    Default appName is "dabo".
    """
    trans = gettext.translation(__lang,__langdir,['.'],fallback=True)
    
    return (p and trans.ngettext(s,p,n)) or trans.gettext(s)

    
def n_(s):
    """ Use it if you want to tell translation service about string
    but don't want to translate it inplace.
    """
    return s

